using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;

namespace Manaddiction.UI
{
    public class GameUIPanel : UIPanel
    {
        public TextMeshProUGUI coin_text;
        
        private static GameUIPanel instance;

        protected override void Awake()
        {
            base.Awake();
            instance = this;
            Show();
        }
        
        protected override void Start()
        {
            base.Start();
    
            // 不要调用 Show()，保持隐藏
            StartCoroutine(DelayedInitPlayerInfo());
        }

        private IEnumerator DelayedInitPlayerInfo()
        {
            yield return new WaitForSeconds(0.1f); // 短暂延迟
    
            if (GameDataManager.Instance != null && GameDataManager.Instance.userData != null)
            {
                UserData udata = GameDataManager.Instance.userData;
                coin_text.text = udata.coins.ToString();
            }
        }
        
        public static GameUIPanel Get()
        {
            return instance;
        }
    }
}
